#!/bin/env python
#_*_coding:utf-8_*_
#Author:swht
#E-mail:qingbo.song@gmail.com
#Date:2015.11.24
#Version:V0.0.1

'''
	网站入口
'''
import re

def welcome():
	flag = 0
	while flag < 5:
		userInput = raw_input('''
	\t\t\t欢迎光临"南非波波小屋"\t\t\t 
	在这里你可以购买二手数码产品，还可以进入信用卡交易中心进行相应操作！
	请选择相应的指令进入不同的界面！
	\t\t二手数码产品:1\t信用卡中心:2\t\t
	请输入你要进入的界面指令[1/2]:''').strip()
		if userInput.isdigit():
			if int(userInput) == 1:
				shop = ShopCenter(u"二手数码产品中心")
				shop.Print()
				shop.shop_login()	
			if int(userInput) == 2:
				bank = Credit(u"信用卡中心")
				bank.Print()
				bank.bank_login()
			if int(userInput) != 1 and int(userInput) != 2:
				print "你输入的指令数字已超出范围!请输入正确的指令[1/2].."
				flag += 1
		else:
			print "系统只接受数字类型指令,请输入正确的指令[1/2]!"
			flag += 1
	print "你输入的错误次数已达5次,程序即将退出!感谢你的使用!"
def LoginSucess(creditId):
	flag = 0
	while flag <= 5:
		print '''
\t=========欢迎用户%s登录到信用卡中心=========
\t\t1.取现\t\t2.查询\t\t
\t\t3.还款\t\t4.转账\t\t
\t\t5.购物\t\t6.退出\t\t
''' % creditId
		choice = int(raw_input('''请选择指令:''').strip())
		if choice >= 1 and choice <= 6:
			if choice == 1:
				print '1'
			if choice == 2:
				print '2'
			if choice == 3:
				print '3'
			if choice == 4: 
				print '4'
			if choice == 5:
				print '5'
			if choice == 6:
				print '6'
		else:
			flag += 1
			print "你输入的指令不在规定范围内,请重新输入![1-6]"


class Center(object):	
	"""docstring for Center"""
	def __init__(self,center):
		self.center = center
	def Print(self):
		print u'''\t\t\t===欢迎光临%s===\t\t\t''' %self.center

#信用卡中心
class Credit(Center):
	"""docstring for Credit"""
	def __init__(self,center):
#		Center.__init__(self,center)
		super(Credit, self).__init__(center)
		self.center = center

	def Print(self):
		Center.Print(self)
		print '''\t\t请登录信用卡中心\t\t'''
	# 判断信用卡信息
	def bank_login(self):
		flage = 0
		while flage <= 3:
			creditId = raw_input("请输入你的信用卡号 :").strip()
			creditPass = raw_input(u"请输入你的信用卡密码:").strip()
			if creditId.isdigit():
				Credit.ifId(creditId,creditPass)
			else:
				print "你输入的信用卡号类型不正确,请重新输入!"
				flage += 1
		print "你输入的错误次数已达3次,程序将退出!"
		welcome()
	def ifId(creditId,creditPass):
		f = file('users.txt','r')
		for list in f.readlines():
			flag = 0
			while flag <= 3:
				if list['ID'] == creditId:
					if list['Pass'] == creditPass:
						LoginSucess(creditId)
					else:
						flag += 1
						print "你输入的密码有误,请重新输入!"
						break
				else:
					flag += 1
					print "你输入的信用卡号有误,请重新输入!"
					break
			print "你的输入错误次数已达3次,登录程序即将退出!"
			welcome()
		f.close()


		

class ShopCenter(Center):
	"""docstring for ShopCenter"""
	def __init__(self,center):
		super(ShopCenter, self).__init__(center)
		self.center = center

	def Print(self):
		Center.Print(self)
		print '''\t\t请登录二手数码产品中心\t\t'''

	#登录信息核对
	def shop_login(self):
		flage = 0
		while flage <= 3:
			userId = raw_input("请输入你的账号:").strip()
			userPass = raw_input(u"请输入你的密码:").strip()
			if  re.match('^[0-9a-zA-Z]+$',userId):
				print "用户信息核对"
			else:
				print "你输入的账户类型不正确,请重新输入!"
				flage += 1
		print "你输入的错误次数已达3次,程序将退出!"
		welcome()

if __name__ == '__main__':
	welcome()